<?php

include_once 'Expression.php';

/**
 * Represents a reference to a constant
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ConstantReferenceExpressionExample.php 
 */

class ConstantReferenceExpression extends Expression
{
    /**
     * The ConstantReferenceExpression constructor
     * @param string $ConstantName 
     */
    
    public function __construct($ConstantName)
    {
        parent::__construct();
        $this->set_ConstantName($ConstantName);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'ConstantName')
        {
            $this->set_ConstantName($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'ConstantName')
        {
            return $this->get_ConstantName();
        }
    }
    
    /**
     * The $ConstantName getter method
     * @return string 
     */
    
    public function get_ConstantName()
    {
        return $this->ConstantName;
    }

    /**
     * The $ConstantName setter method
     * @param string $VariableName
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert (false) throws InvalidArgumentException
     * @assert (new stdClass()) throws InvalidArgumentException
     */
    
    public function set_ConstantName($ConstantName)
    {
        if(is_string($ConstantName))
        {
            $this->ConstantName = $ConstantName;
        }
        else
        {
            throw new InvalidArgumentException(
                'The variable name must be a string.');
        }
    }

    /**
     * The name of the constant
     * @var string 
     */
    
    private $ConstantName;
}

?>
